
version 15
capture log close
set more off
clear
clear matrix
clear mata

if c(username)=="WB485280" {
		glo rootdir		"C:\Users\wb485280\OneDrive - WBG\radicalization"
		}
if c(username)=="WB382635" {
		glo rootdir		"C:\Users\wb382635\Dropbox\Unemp & daesh"
		}
if c(username)=="WB452275" {
		glo rootdir		"C:\Users\WB452275\Dropbox\Projects\Unemp & daesh"
		}
if c(username)=="sarurchaudhary" {
		glo rootdir		"/Users/sarurchaudhary/Dropbox/Unemp & daesh"
		}
if c(username)=="kartikabhatia" {
			glo rootdir		"/Users/kartikabhatia/Dropbox/Before2019/Unemp & daesh"
			}
			
		glo	datadir     "${rootdir}/Data/Raw data"
		glo outdir		"${rootdir}/Data/Working datasets"
		glo dodir		"${rootdir}/Dofiles"
        
		cd "${outdir}"
		

	    log using gallup3_prep, replace t

 
* ------------------------------------------------------------------------------
* Date : July 2017 [chkd oct 2021]


* Project : Mena Economic Monitor, Working paper (MNACE, The World Bank)


* This do file prepares the Gallup variables by education and muslim vars to merge

* Database used : The_Gallup_032516.dta.dta


* Output : gallup3.dta

* ------------------------------------------------------------------------------



*                      ---------------------------
*                      --------GALLUP Data--------
*                      ---------------------------

use "${datadir}/The_Gallup_032516.dta", clear
rename WP* wp*

*           =================
*           Variables to keep
*           =================


***Religion

/* WP119 Is religion an important part of your daily life?
   1 "1 Yes"
   2 "2 No"
   3 "3 (DK)"
   4 "4 (Refused)"; */
  
recode wp119 (3=.a) (4=.d)  


***Education

/*wp3117. What is your highest completed level of education?
 1 "1 Completed elementary education or less (up to 8 years of basic education)"
   2 "2 Secondary - 3 year Secondary education and some education beyond secondary education (9-15 years of educat"
   3 "3 Completed four years of education beyond high school and/or received a 4-year college degree."
   4 "4 (DK)"
   5 "5 (RF)";*/

recode wp3117 (4=.a) (5=.d)
label define ps 1 "primary" 2 "secondary" 3 "tertiary" 
label values wp3117 ps
tab wp3117


 
 ***Age
drop if wp1220<15
recode wp1220 (100=.d)
gen young=0 
replace young=1 if wp1220<=40
replace young=. if wp1220==.d //dropping people who refused to answer the question
replace young=. if wp1220==.  //dropping missing obs

gen adult=0
replace adult=1 if wp1220<=64
replace adult=. if wp1220==.d //dropping people who refused to answer the question
replace adult=. if wp1220==.  //dropping missing obs

* ------------------------------------------------------------------------------

* Creating religiosity variables among muslim respondents only
gen mus_dummy=.
replace mus_dummy=1 if wp1233Recoded==2
replace mus_dummy=0 if wp1233Recoded==1
replace mus_dummy=0 if wp1233Recoded==3
replace mus_dummy=0 if wp1233Recoded==4
replace mus_dummy=0 if wp1233Recoded==5
replace mus_dummy=0 if wp1233Recoded==6
replace mus_dummy=0 if wp1233Recoded==7
replace mus_dummy=. if wp1233Recoded==8 //dopping people who did not respond or missing obs

gen religiosity_dummy=.
replace religiosity_dummy=1 if wp119==1
replace religiosity_dummy=0 if wp119==2

gen g_religiosity_mus=mus_dummy*religiosity_dummy


* Creating religiosity variables among muslim respondents and by education status

gen prim_dummy=.
replace prim_dummy=1 if wp3117==1 
replace prim_dummy=0 if wp3117==2 
replace prim_dummy=0 if wp3117==3 

gen sec_dummy=.
replace sec_dummy=1 if wp3117==2
replace sec_dummy=0 if wp3117==1
replace sec_dummy=0 if wp3117==3

gen tert_dummy=.
replace tert_dummy=1 if wp3117==3
replace tert_dummy=0 if wp3117==1
replace tert_dummy=0 if wp3117==2

gen g_religiosity_mus_prim=mus_dummy*religiosity_dummy*prim_dummy
gen g_religiosity_mus_sec =mus_dummy*religiosity_dummy*sec_dummy
gen g_religiosity_mus_tert=mus_dummy*religiosity_dummy*tert_dummy

* Creating religiosity variables that vary by education status

gen g_religiosity_prim=religiosity_dummy*prim_dummy
gen g_religiosity_sec =religiosity_dummy*sec_dummy
gen g_religiosity_tert=religiosity_dummy*tert_dummy

* create male (wp1219) , muslim, between ages 15-40 by education status (wp3117)

gen male_dummy=.
replace male_dummy=1 if wp1219==1
replace male_dummy=0 if wp1219==2


gen g_prop_male_mus_young_prim=young*mus_dummy*male_dummy*prim_dummy
gen g_prop_male_mus_young_sec =young*mus_dummy*male_dummy*sec_dummy
gen g_prop_male_mus_young_tert=young*mus_dummy*male_dummy*tert_dummy

gen g_prop_male_prim=male_dummy*prim_dummy
gen g_prop_male_sec =male_dummy*sec_dummy
gen g_prop_male_tert=male_dummy*tert_dummy

gen g_prop_prim=prim_dummy
gen g_prop_sec =sec_dummy
gen g_prop_tert=tert_dummy

gen g_prop_male_mus_prim=adult*mus_dummy*male_dummy*prim_dummy
gen g_prop_male_mus_sec =adult*mus_dummy*male_dummy*sec_dummy
gen g_prop_male_mus_tert=adult*mus_dummy*male_dummy*tert_dummy

*ADDED BY CLEMENT 4/19/2017

* create unemployment rate measures
codebook EMP_UNEMP male_dummy mus_dummy young prim_dummy sec_dummy tert_dummy if YEAR_CALENDAR==2013

*1.	Total
*	a.	Total
gen g_unemp=EMP_UNEMP

*	b.	Among males only
gen g_unemp_male     =EMP_UNEMP*male_dummy
replace g_unemp_male=. if male_dummy==0

*	c.	Among Muslim males only
gen g_unemp_male_mus     =EMP_UNEMP*male_dummy*mus_dummy
replace g_unemp_male_mus=. if male_dummy==0 | mus_dummy==0

*	d.	Among Muslim males under 40 only
gen g_unemp_male_mus_young     =EMP_UNEMP*male_dummy*mus_dummy*young
replace g_unemp_male_mus_young=. if male_dummy==0 | mus_dummy==0 | young==0

*2.	By education category (1, 2, 3)
*	a.	Total

gen g_unemp_prim=EMP_UNEMP*prim_dummy
replace g_unemp_prim=. if prim_dummy==0

gen g_unemp_sec =EMP_UNEMP*sec_dummy
replace g_unemp_sec=. if sec_dummy==0

gen g_unemp_tert=EMP_UNEMP*tert_dummy
replace g_unemp_tert=. if tert_dummy==0

*	b.	Among male only

gen g_unemp_male_prim=EMP_UNEMP*male_dummy*prim_dummy
replace g_unemp_male_prim=. if male_dummy==0 | prim_dummy==0

gen g_unemp_male_sec =EMP_UNEMP*male_dummy*sec_dummy
replace g_unemp_male_sec=. if male_dummy==0 | sec_dummy==0

gen g_unemp_male_tert=EMP_UNEMP*male_dummy*tert_dummy
replace g_unemp_male_tert=. if male_dummy==0 | tert_dummy==0

*	c.	Among Muslim males only

gen g_unemp_male_mus_prim=EMP_UNEMP*male_dummy*mus_dummy*prim_dummy
replace g_unemp_male_mus_prim=. if male_dummy==0 | prim_dummy==0 | mus_dummy==0

gen g_unemp_male_mus_sec =EMP_UNEMP*male_dummy*mus_dummy*sec_dummy
replace g_unemp_male_mus_sec=. if male_dummy==0 | sec_dummy==0 | mus_dummy==0

gen g_unemp_male_mus_tert=EMP_UNEMP*male_dummy*mus_dummy*tert_dummy
replace g_unemp_male_mus_tert=. if male_dummy==0 | tert_dummy==0 | mus_dummy==0

*	d.	Among Muslim males under 40 only

gen g_unemp_male_mus_young_prim=EMP_UNEMP*male_dummy*mus_dummy*young*prim_dummy
replace g_unemp_male_mus_young_prim=. if male_dummy==0 | prim_dummy==0 | mus_dummy==0 | young==0

gen g_unemp_male_mus_young_sec =EMP_UNEMP*male_dummy*mus_dummy*young*sec_dummy
replace g_unemp_male_mus_young_sec=. if male_dummy==0 | sec_dummy==0 | mus_dummy==0 | young==0

gen g_unemp_male_mus_young_tert=EMP_UNEMP*male_dummy*mus_dummy*young*tert_dummy
replace g_unemp_male_mus_young_tert=. if male_dummy==0 | tert_dummy==0 | mus_dummy==0 | young==0


* ------------------------------------------------------------------------------

* Collapsing data to create country-year panel

collapse young - g_unemp_male_mus_young_tert [pw=wgt], by(countrynew YEAR_CALENDAR)

* ------------------------------------------------------------------------------

 rename YEAR_CALENDAR year

label variable g_religiosity_mus "prop of muslims who consider religion an imp part of their daily life"
label variable g_religiosity_mus_prim "prop of primary educated muslims who consider religion an imp part of their daily life"
label variable g_religiosity_mus_sec "prop of secondary educated muslims who consider religion an imp part of their daily life"
label variable g_religiosity_mus_tert "prop of tertiary educated muslims who consider religion an imp part of their daily life"

label variable g_religiosity_prim "prop of primary educated  who consider religion an imp part of their daily life"
label variable g_religiosity_sec "prop of secondary educated  who consider religion an imp part of their daily life"
label variable g_religiosity_tert "prop of tertiary educated  who consider religion an imp part of their daily life"


label variable g_prop_male_mus_young_prim "prop. of muslim young males with primary edcuation "
label variable g_prop_male_mus_young_sec "prop. of muslim young males with secondary edcuation "
label variable g_prop_male_mus_young_tert "prop. of muslim young males with tertiary edcuation "

label variable g_prop_male_mus_prim "prop. of muslim adult males with primary edcuation "
label variable g_prop_male_mus_sec "prop. of muslim adult males with secondary edcuation "
label variable g_prop_male_mus_tert "prop. of muslim adult males with tertiary edcuation "

label variable g_unemp "unemployment rate from gallup surveys"
label variable g_unemp_male "unemployment rate among males from gallup surveys"
label variable g_unemp_male_mus "unemployment rate among muslim males from gallup surveys"
label variable g_unemp_male_mus_young "unemployment rate among muslim males under 40 from gallup surveys"

label variable g_unemp_prim "unemployment rate among the primary educated from gallup surveys"
label variable g_unemp_male_prim "unemployment rate among primary educated males from gallup surveys"
label variable g_unemp_male_mus_prim "unemployment rate among primary educated muslim males from gallup surveys"
label variable g_unemp_male_mus_young_prim "unemployment rate among primary educated muslim males under 40 from gallup surveys"

label variable g_unemp_sec "unemployment rate among the secondary educated from gallup surveys"
label variable g_unemp_male_sec "unemployment rate among secondary educated males from gallup surveys"
label variable g_unemp_male_mus_sec "unemployment rate among secondary educated muslim males from gallup surveys"
label variable g_unemp_male_mus_young_sec "unemployment rate among secondary educated muslim males under 40 from gallup surveys"

label variable g_unemp_tert "unemployment rate among the tertiary educated from gallup surveys"
label variable g_unemp_male_tert "unemployment rate among tertiary educated males from gallup surveys"
label variable g_unemp_male_mus_tert "unemployment rate among tertiary educated muslim males from gallup surveys"
label variable g_unemp_male_mus_young_tert "unemployment rate among tertiary educated muslim males under 40 from gallup surveys"

save temp, replace

*----------------------------------------------------------------------------------------------------------------------------------


* Adding countries that are in WDI but not in gallup

 insobs 55, before(1)
 replace countrynew = "Equatorial Guinea" in 1/11
 replace year = 2005 in 1
 replace year = year[_n-1]+1  in 2/11

 replace countrynew = "Eritrea" in 12/22
 replace year = 2005 in 12
 replace year = year[_n-1]+1  in 13/22

 replace countrynew = "Gambia, The" in 23/33
 replace year = 2005 in 23
 replace year = year[_n-1]+1  in 24/33

 replace countrynew = "Guinea-Bissau" in 34/44
 replace year = 2005 in 34
 replace year = year[_n-1]+1  in 35/44

 replace countrynew = "North Korea" in 45/55
 replace year = 2005 in 45
 replace year = year[_n-1]+1  in 46/55


 * Creating numeric variable for countries

sort countrynew, stable
encode countrynew, gen(ctry)

sort ctry year

*Note: some countries were not asked the religion question in 2013. replacing with 2012 value.
*Ethiopia has ter dummy =0 for 2013


tsset ctry year
local varlist =  "young adult mus_dummy prim_dummy sec_dummy tert_dummy male_dummy g_prop_male_mus_young_prim g_prop_male_mus_young_sec g_prop_male_mus_young_tert g_prop_male_mus_prim g_prop_male_mus_sec g_prop_male_mus_tert g_unemp g_unemp_male g_unemp_male_mus g_unemp_male_mus_young g_unemp_prim g_unemp_sec g_unemp_tert g_unemp_male_prim g_unemp_male_sec g_unemp_male_tert g_unemp_male_mus_prim g_unemp_male_mus_sec g_unemp_male_mus_tert g_unemp_male_mus_young_prim g_unemp_male_mus_young_sec g_unemp_male_mus_young_tert"
codebook `varlist' if year==2013

foreach var in `varlist' {

replace `var'=l1.`var' if year ==2013 & `var'==.
replace `var'=f1.`var' if year ==2013 & `var'==. & l1.`var'==.
}

codebook `varlist' if year==2013
/*
replace g_prop_male_mus_young_prim=g_prop_male_mus_young_prim[_n-1] if  g_prop_male_mus_young_prim==.
replace g_prop_male_mus_young_sec =g_prop_male_mus_young_sec[_n-1]  if  g_prop_male_mus_young_sec ==. 
replace g_prop_male_mus_young_tert=g_prop_male_mus_young_tert[_n-1] if  g_prop_male_mus_young_tert==. 

replace g_prop_male_mus_prim=g_prop_male_mus_prim[_n-1] if g_prop_male_mus_prim==. 
replace g_prop_male_mus_sec =g_prop_male_mus_sec[_n-1]  if g_prop_male_mus_sec ==. 
replace g_prop_male_mus_tert=g_prop_male_mus_tert[_n-1] if g_prop_male_mus_tert==. 
*/

save "${outdir}/gallup3.dta", replace

log close
